<script>
	import { updateReadStatus } from '@/api/platform/common.js'
	import { getFormInfo, getTaskInfo } from '@/api/base/flow.js'
	import { utilities } from '@/utils/common.js'
	import * as nfcUtil from '@/utils/nfc.js'
	import project from '@/utils/config/project.js'
	
	export default {
		onLaunch: function() {
			console.log('App Launch')
			
			// #ifdef APP-PLUS  
			plus.push.addEventListener('click', message => {
				//清除app角标
				plus.runtime.setBadgeNumber(0);
				// 判断是否登录，如果已登录，直接跳转，否则跳转登录页
				if(uni.getStorageSync("_app_token")) {
					getFormInfo(message.payload.bizKey).then(res=>{
						let taskId = res.data.endProcessTaskId
						let url = res.data.formModel.mobileValue
						
						getTaskInfo(taskId).then(res=>{
							let nodeId = res.data.nodeId
							
							uni.navigateTo({
								url: url + "&type=approve&taskId=" + taskId + "&nodeId=" + nodeId + "&sourceType=online"
							})
						})
					})
				} else {
					uni.reLaunch({
						url: "/pages/platform/login/index?type=offline&msgData=" + JSON.stringify(message.payload)
					})
				}
				// 将消息更新为已读
				let param = {
					messageId: message.payload.messageId,
					isReaded: 'Y'
				}
				updateReadStatus(param)
			});
			plus.push.addEventListener('receive', message => {
				plus.push.createMessage(message.content)
			});
			
			// 锁定竖屏
			plus.screen.lockOrientation("portrait-primary");
			// #endif
		},
		onShow: function() {
			console.log('App Show')
			
			// 获取版本
			if(project.NEED_UPGRADE) {
				utilities.getAppVersion()
				let currentVersion = uni.getStorageSync("currentVersion")
				let latestVersion = uni.getStorageSync("latestVersion")
				if(utilities.compareVersion(currentVersion, latestVersion.appVersion) == -1) {
					uni.navigateTo({
						url: '/pages/base/updateModel'
					})
				}
			}
		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>
<style lang="scss">
	/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
	@import "@/uni_modules/uview-ui/index.scss";
</style>
<style>
	/*每个页面公共css */
	@import "/static/style/cpis-icon.scss";
</style>
